package com.dreamsky.life.interceptor;

import java.util.Arrays;

import com.jfinal.core.Controller;
import com.jfinal.kit.JsonKit;
import com.jfinal.validate.Validator;

public class ElectricControlValidator extends Validator {

	@Override
	protected void validate(Controller me) {
		String key = getActionKey();

		if (key.indexOf("controlState") != -1) {
			validateRequired("electricControl.ele_id", "eleIdError",
					"ele id vlidate");
			validateRequired("electricControl.cl_employ", "clEmployError",
					"control employ vlidate");
			return;
		}

		if (key.indexOf("electric") != -1) {
			validateRequired("userId", "idError", "id vlidate");
			return;
		}

		if (key.indexOf("sendState") != -1) {
			validateRequired("electricControl.id", "conIdError",
					"ele id vlidate");
			validateRequired("electricControl.re_employ", "employError",
					"state vlidate");
			return;
		}

	}

	@Override
	protected void handleError(Controller me) {
		String key = getActionKey();
		String[] errorArray = null;
		me.setAttr("success", false);

		if (key.indexOf("controlState") != -1) {
			errorArray = new String[] { "eleIdError", "clEmployError" };
			return;
		}

		if (key.indexOf("electric") != -1) {
			errorArray = new String[] { "success", "idError" };
		}

		if (key.indexOf("sendState") != -1) {
			errorArray = new String[] { "success", "conIdError", "employError" };
			return;
		}

		me.renderJson(errorArray);
	}

}
